﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once

#include "UnitTestImp.h"


#define MAKE_TEST_CLASS_NAME(testName, testCaseName) \
    G##testName##testCaseName##Test

#define MAKE_REGISTER_TEST_NAME(testName, testCaseName) \
    Register##testName##testCaseName##Test

#define MAKE_TEST_CLASS_NAME_WITH_TAG(testName, testCaseName, testCaseTag) \
    G##testName##testCaseName##testCaseTag##Test

#define MAKE_REGISTER_TEST_NAME_WITH_TAG(testName, testCaseName, testCaseTag) \
    Register##testName##testCaseName##testCaseTag##Test

namespace gtest
{
// 添加使用自定义测试夹具的测试用例。测试夹具需要预先定义
#define TEST_USING_FIXTURE(testName, testCaseName, testFixtureClass) \
    class MAKE_TEST_CLASS_NAME(testName, testCaseName) : public gtest::testFixtureClass { \
    private: \
        virtual void Test() override; \
    public: \
        MAKE_TEST_CLASS_NAME(testName, testCaseName)() : gtest::testFixtureClass(WSTRING_OF(testName), WSTRING_OF(testCaseName)) { } \
    }; \
    void MAKE_REGISTER_TEST_NAME(testName, testCaseName)() { \
        static G##testName##testCaseName##Test testFixture; \
        gtest::GTestManager::GetInstance()->AddTestFixture(&testFixture); \
    } \
    gcmp::OneTimeInitializer theInitializerOf##Register##testName##testCaseName##Test(&MAKE_REGISTER_TEST_NAME(testName, testCaseName));\
    void MAKE_TEST_CLASS_NAME(testName, testCaseName)::Test()

// 添加测试用例
#define TEST(testName, testCaseName) \
    TEST_USING_FIXTURE(testName, testCaseName, GTestFixture)


#define TEST_USING_FIXTURE_WITH_TAG(testName, testCaseName, testCaseTag, testFixtureClass) \
    class MAKE_TEST_CLASS_NAME_WITH_TAG(testName, testCaseName, testCaseTag) : public gtest::testFixtureClass { \
    private: \
        virtual void Test() override; \
    public: \
        MAKE_TEST_CLASS_NAME_WITH_TAG(testName, testCaseName, testCaseTag)() : gtest::testFixtureClass(WSTRING_OF(testName), WSTRING_OF(testCaseName), WSTRING_OF(testCaseTag)) { } \
    }; \
    void MAKE_REGISTER_TEST_NAME_WITH_TAG(testName, testCaseName, testCaseTag)() { \
        static G##testName##testCaseName##testCaseTag##Test testFixture; \
        gtest::GTestManager::GetInstance()->AddTestFixture(&testFixture); \
    } \
    gcmp::OneTimeInitializer theInitializerOf##Register##testName##testCaseName##testCaseTag##Test(&MAKE_REGISTER_TEST_NAME_WITH_TAG(testName, testCaseName, testCaseTag));\
    void MAKE_TEST_CLASS_NAME_WITH_TAG(testName, testCaseName, testCaseTag)::Test()

#define TEST_WITH_TAG(testName, testCaseName, testCaseTag) \
    TEST_USING_FIXTURE_WITH_TAG(testName, testCaseName, testCaseTag, GTestFixture)
}
